import Vue from "vue";
import Vuex from "vuex";
Vue.use(Vuex);
import { $getStaticUrl } from "@/core/util.js";
import { $get } from "@/core/request";
import order from "./modules/order";

export default new Vuex.Store({
	state: {
		wxConfig: {
			state: 0,
		},
	},
	mutations: {
		SET_WX_CONFIG(state, data) {
			state.wxConfig = data;
		},
	},
	actions: {
		async getWXConfig({ commit }) {
			let { data } = await $get("/system/mini/version", {}, false);
			if (data) commit("SET_WX_CONFIG", data);
		},
		async getCount({ commit, state }) {
			let { data } = await $get("/notice/unread-count");
			if (data) {
				const mesPage = state.tabbarList.find(
					(t) => t.pagePath === "/pages/main/tabbar/mine/mine"
				);
				mesPage.count = data;
				commit("SET_TABBAR_LIST", mesPage);
			}
		},
	},
	modules: {
		order,
	},
});
